#include <fun.h>

#define ID_NUM 301
// uchar CardType[2] = {0x00, 0x0};
// uchar UID[4] = {0x00, 0x00, 0x00, 0x00};
uchar xdata g_ucTempbuf[20];
const uchar xdata UIDlist[ID_NUM][4] = {
{0x8A,0x27,0x37,0x04},
{0x8A,0x3D,0x50,0x04},
{0x8A,0x2F,0x78,0x04},
{0x8A,0x27,0x13,0x04},
{0x8A,0x2C,0x80,0x04},
{0x8A,0x3E,0x46,0x04},
{0x8A,0x2B,0xAC,0x04},
{0x8A,0x2D,0x71,0x04},
{0x8A,0x3D,0xA8,0x04},
{0x8A,0x3D,0x70,0x04},
{0x8A,0x3E,0x6A,0x04},
{0x8A,0x2B,0xB8,0x04},
{0x8A,0x2C,0x45,0x04},
{0x8A,0x2D,0x8D,0x04},
{0x8A,0x2D,0x43,0x04},
{0x8A,0x27,0x26,0x04},
{0x8A,0x2C,0x5C,0x04},
{0x8A,0x27,0x3D,0x04},
{0x8A,0x2F,0x5E,0x04},
{0x8A,0x27,0xDB,0x04},
{0x8A,0x3D,0xD3,0x04},
{0x8A,0x2F,0xBB,0x04},
{0x8A,0x3D,0xE2,0x04},
{0x8A,0x2F,0xAA,0x04},
{0x8A,0x3E,0x4D,0x04},
{0x8A,0x2C,0x4D,0x04},
{0x8A,0x2F,0x49,0x04},
{0x8A,0x2B,0xA9,0x04},
{0x8A,0x2D,0xBE,0x04},
{0x8A,0x27,0xF0,0x04},
{0x8A,0x2E,0x57,0x04},
{0x8A,0x3D,0xCC,0x04},
{0x8A,0x3D,0x0D,0x04},
{0x8A,0x27,0xC3,0x04},
{0x8A,0x2D,0x84,0x04},
{0x8A,0x26,0x4F,0x04},
{0x8A,0x3D,0x12,0x04},
{0x8A,0x3E,0x62,0x04},
{0x8A,0x3D,0x78,0x04},
{0x8A,0x3D,0xED,0x04},
{0x8A,0x3D,0x1A,0x04},
{0x8A,0x3E,0x48,0x04},
{0x8A,0x44,0x8E,0x04},
{0x8A,0x2F,0x75,0x04},
{0x8A,0x27,0x4D,0x04},
{0x8A,0x3D,0x5C,0x04},
{0x8A,0x3D,0x6C,0x04},
{0x8A,0x3D,0x07,0x04},
{0x8A,0x2B,0x73,0x04},
{0x8A,0x2B,0x55,0x04},
{0x8A,0x2C,0x55,0x04},
{0x8A,0x2C,0x54,0x04},
{0x8A,0x2F,0x93,0x04},
{0x8A,0x27,0xD7,0x04},
{0x8A,0x3D,0x8B,0x04},
{0x8A,0x3D,0x7D,0x04},
{0x8A,0x3E,0x47,0x04},
{0x8A,0x2F,0x87,0x04},
{0x8A,0x2B,0xB3,0x04},
{0x8A,0x3D,0x52,0x04},
{0x8A,0x2F,0xC9,0x04},
{0x8A,0x2B,0xB6,0x04},
{0x8A,0x2D,0xA8,0x04},
{0x8A,0x27,0xBB,0x04},
{0x8A,0x2D,0xA6,0x04},
{0x8A,0x3D,0xA2,0x04},
{0x8A,0x2C,0x6F,0x04},
{0x8A,0x3D,0x21,0x04},
{0x8A,0x2D,0x61,0x04},
{0x8A,0x2D,0x44,0x04},
{0x8A,0x2F,0x65,0x04},
{0x8A,0x3D,0x3F,0x04},
{0x8A,0x27,0xDA,0x04},
{0x8A,0x2B,0x49,0x04},
{0x8A,0x3D,0xAE,0x04},
{0x8A,0x3D,0x28,0x04},
{0x8A,0x2F,0xB1,0x04},
{0x8A,0x3E,0x50,0x04},
{0x8A,0x3E,0x87,0x04},
{0x8A,0x3D,0xDC,0x04},
{0x8A,0x3D,0xE1,0x04},
{0x8A,0x2D,0x81,0x04},
{0x8A,0x27,0xCA,0x04},
{0x8A,0x3D,0x5F,0x04},
{0x8A,0x2D,0xA5,0x04},
{0x8A,0x3D,0xCB,0x04},
{0x8A,0x3E,0x59,0x04},
{0x8A,0x2F,0x51,0x04},
{0x8A,0x3E,0x8A,0x04},
{0x8A,0x2D,0x5A,0x04},
{0x8A,0x3D,0xDD,0x04},
{0x8A,0x2F,0x86,0x04},
{0x8A,0x3D,0x27,0x04},
{0x8A,0x2C,0x75,0x04},
{0x8A,0x30,0x42,0x04},
{0x8A,0x2B,0x4A,0x04},
{0x8A,0x2D,0x4F,0x04},
{0x8A,0x3F,0x60,0x04},
{0x8A,0x27,0xBD,0x04},
{0x8A,0x2F,0x8C,0x04},
{0x8A,0x2F,0xDA,0x04},
{0x8A,0x2C,0x6A,0x04},
{0x8A,0x2D,0x74,0x04},
{0x8A,0x2E,0x6C,0x04},
{0x8A,0x3D,0x0F,0x04},
{0x8A,0x2B,0x6E,0x04},
{0x8A,0x2F,0x4F,0x04},
{0x8A,0x26,0x32,0x04},
{0x8A,0x2D,0x65,0x04},
{0x8A,0x27,0x36,0x04},
{0x8A,0x3D,0xEA,0x04},
{0x8A,0x30,0x46,0x04},
{0x8A,0x2B,0x92,0x04},
{0x8A,0x2F,0xBF,0x04},
{0x8A,0x27,0x47,0x04},
{0x8A,0x2F,0x46,0x04},
{0x8A,0x2F,0x42,0x04},
{0x8A,0x2D,0x7E,0x04},
{0x8A,0x27,0x03,0x04},
{0x8A,0x3E,0x49,0x04},
{0x8A,0x27,0x0E,0x04},
{0x8A,0x2C,0x7E,0x04},
{0x8A,0x2D,0xBC,0x04},
{0x8A,0x3E,0x7C,0x04},
{0x8A,0x27,0xFA,0x04},
{0x8A,0x3D,0xAD,0x04},
{0x8A,0x27,0xBF,0x04},
{0x8A,0x26,0x4B,0x04},
{0x8A,0x3D,0x89,0x04},
{0x8A,0x27,0xEE,0x04},
{0x8A,0x2C,0x72,0x04},
{0x8A,0x2B,0xAD,0x04},
{0x8A,0x2B,0xA7,0x04},
{0x8A,0x3D,0x98,0x04},
{0x8A,0x2D,0x92,0x04},
{0x8A,0x2F,0x45,0x04},
{0x8A,0x3D,0x8F,0x04},
{0x8A,0x2F,0xD4,0x04},
{0x8A,0x3E,0x4A,0x04},
{0x8A,0x3E,0x85,0x04},
{0x8A,0x3E,0x5F,0x04},
{0x8A,0x3D,0xC6,0x04},
{0x8A,0x2D,0x54,0x04},
{0x8A,0x3D,0x73,0x04},
{0x8A,0x3D,0x5A,0x04},
{0x8A,0x3D,0xE0,0x04},
{0x8A,0x27,0x2A,0x04},
{0x8A,0x2D,0x57,0x04},
{0x8A,0x49,0x63,0x04},
{0x8A,0x2F,0xCA,0x04},
{0x8A,0x3D,0x3A,0x04},
{0x8A,0x3D,0x6F,0x04},
{0x8A,0x3D,0x97,0x04},
{0x8A,0x3D,0x93,0x04},
{0x8A,0x3E,0x4C,0x04},
{0x8A,0x3D,0x90,0x04},
{0x8A,0x2B,0x8C,0x04},
{0x8A,0x30,0x45,0x04},
{0x8A,0x2D,0x96,0x04},
{0x8A,0x2E,0x60,0x04},
{0x8A,0x27,0x06,0x04},
{0x8A,0x3E,0x40,0x04},
{0x8A,0x2B,0x6F,0x04},
{0x8A,0x2B,0x70,0x04},
{0x8A,0x27,0xF2,0x04},
{0x8A,0x2D,0x9F,0x04},
{0x8A,0x27,0x15,0x04},
{0x8A,0x3D,0xAF,0x04},
{0x8A,0x27,0x28,0x04},
{0x8A,0x3D,0xFB,0x04},
{0x8A,0x27,0xF9,0x04},
{0x8A,0x2C,0x59,0x04},
{0x8A,0x27,0x46,0x04},
{0x8A,0x2E,0x6D,0x04},
{0x8A,0x3D,0x31,0x04},
{0x8A,0x27,0x34,0x04},
{0x8A,0x27,0xD2,0x04},
{0x8A,0x3D,0x88,0x04},
{0x8A,0x3D,0xB8,0x04},
{0x8A,0x2B,0xB5,0x04},
{0x8A,0x2F,0xC8,0x04},
{0x8A,0x27,0x07,0x04},
{0x8A,0x3E,0x56,0x04},
{0x8A,0x2E,0x48,0x04},
{0x8A,0x2E,0x4C,0x04},
{0x8A,0x2D,0x60,0x04},
{0x8A,0x2C,0x7B,0x04},
{0x8A,0x2D,0xB0,0x04},
{0x8A,0x2C,0x73,0x04},
{0x8A,0x3D,0xDF,0x04},
{0x8A,0x2C,0x56,0x04},
{0x8A,0x2B,0xA6,0x04},
{0x8A,0x27,0xF1,0x04},
{0x8A,0x27,0xE3,0x04},
{0x8A,0x2F,0x48,0x04},
{0x8A,0x27,0x14,0x04},
{0x8A,0x2D,0xB9,0x04},
{0x8A,0x2F,0xC0,0x04},
{0x8A,0x26,0x47,0x04},
{0x8A,0x27,0x18,0x04},
{0x8A,0x2D,0x50,0x04},
{0x8A,0x2F,0x9E,0x04},
{0x8A,0x26,0x4A,0x04},
{0x8A,0x2D,0x9C,0x04},
{0x8A,0x3E,0x8C,0x04},
{0x8A,0x2D,0xA1,0x04},
{0x8A,0x3D,0xBF,0x04},
{0x8A,0x2F,0xCB,0x04},
{0x8A,0x2B,0xA5,0x04},
{0x8A,0x2E,0x42,0x04},
{0x8A,0x2F,0xD5,0x04},
{0x8A,0x3E,0x71,0x04},
{0x8A,0x3D,0x42,0x04},
{0x8A,0x2B,0xBA,0x04},
{0x8A,0x3D,0xF9,0x04},
{0x8A,0x2C,0x5B,0x04},
{0x8A,0x2D,0x4C,0x04},
{0x8A,0x2B,0xA3,0x04},
{0x8A,0x3D,0xA7,0x04},
{0x8A,0x2D,0x4A,0x04},
{0x8A,0x2B,0x62,0x04},
{0x8A,0x27,0x10,0x04},
{0x8A,0x3D,0xD9,0x04},
{0x8A,0x3D,0xC1,0x04},
{0x8A,0x2B,0x87,0x04},
{0x8A,0x2D,0xAF,0x04},
{0x8A,0x2C,0x4E,0x04},
{0x8A,0x3D,0x80,0x04},
{0x8A,0x3E,0x58,0x04},
{0x8A,0x2F,0xC6,0x04},
{0x8A,0x3D,0x37,0x04},
{0x8A,0x2E,0x64,0x04},
{0x8A,0x2F,0x3F,0x04},
{0x8A,0x2D,0xBA,0x04},
{0x8A,0x2F,0x7B,0x04},
{0x8A,0x3E,0x73,0x04},
{0x8A,0x2E,0x5A,0x04},
{0x8A,0x3E,0x5E,0x04},
{0x8A,0x3E,0x43,0x04},
{0x8A,0x3D,0xC5,0x04},
{0x8A,0x27,0xDD,0x04},
{0x8A,0x2F,0x5D,0x04},
{0x8A,0x2E,0x58,0x04},
{0x8A,0x2D,0x77,0x04},
{0x8A,0x30,0x43,0x04},
{0x8A,0x27,0xF6,0x04},
{0x8A,0x2B,0x67,0x04},
{0x8A,0x2D,0x53,0x04},
{0x8A,0x3D,0x91,0x04},
{0x8A,0x27,0x42,0x04},
{0x8A,0x27,0xD5,0x04},
{0x8A,0x2B,0x5B,0x04},
{0x8A,0x2B,0x96,0x04},
{0x8A,0x3E,0x72,0x04},
{0x8A,0x3D,0x58,0x04},
{0x8A,0x3D,0xA9,0x04},
{0x8A,0x2F,0xA4,0x04},
{0x8A,0x3D,0x43,0x04},
{0x8A,0x3D,0xD4,0x04},
{0x8A,0x3E,0x44,0x04},
{0x8A,0x2B,0x4B,0x04},
{0x8A,0x2F,0x61,0x04},
{0x8A,0x2E,0x70,0x04},
{0x8A,0x3D,0xF5,0x04},
{0x8A,0x2F,0xCF,0x04},
{0x8A,0x27,0xCB,0x04},
{0x8A,0x2B,0xB7,0x04},
{0x8A,0x3D,0x19,0x04},
{0x8A,0x2D,0x52,0x04},
{0x8A,0x27,0xD0,0x04},
{0x8A,0x2B,0xA8,0x04},
{0x8A,0x3D,0x9D,0x04},
{0x8A,0x3D,0x2A,0x04},
{0x8A,0x27,0xC2,0x04},
{0x8A,0x3D,0x1D,0x04},
{0x8A,0x2B,0x91,0x04},
{0x8A,0x2D,0x5C,0x04},
{0x8A,0x3E,0x54,0x04},
{0x8A,0x3D,0xA5,0x04},
{0x8A,0x2B,0x48,0x04},
{0x8A,0x2D,0xBB,0x04},
{0x8A,0x27,0xFC,0x04},
{0x8A,0x3D,0xD0,0x04},
{0x8A,0x2D,0xC0,0x04},
{0x8A,0x2D,0x47,0x04},
{0x8A,0x2B,0x76,0x04},
{0x8A,0x3D,0xA6,0x04},
{0x8A,0x2F,0x80,0x04},
{0x8A,0x30,0x3F,0x04},
{0x8A,0x2C,0x61,0x04},
{0x8A,0x3E,0x6F,0x04},
{0x8A,0x2F,0x53,0x04},
{0x8A,0x2D,0x48,0x04},
{0x8A,0x2B,0x7F,0x04},
{0x8A,0x2B,0x9F,0x04},
{0x8A,0x3D,0xCD,0x04},
{0x8A,0x27,0x3C,0x04},
{0x8A,0x2E,0x50,0x04},
{0x8A,0x2F,0x6E,0x04},
{0x8A,0x2B,0x81,0x04},
{0x8A,0xDA,0x7C,0x04}
};

/**延时 n ms
 * n：n ms
 */ 
void delay1(uint n)
{
    uchar i, j;
    while (n--) {
        i = 15;
        j = 90;
        do
        {
            while (--j);
        } while (--i);
    }
}
/**寻找指定UID的卡号
 * UID：需要匹配的卡号
 */
bit FindUID(char *UID)
{
    char* UID_Temp = UID;
	uchar xdata i,k;
    for (i = 0; i < ID_NUM; i ++)
    {
        UID_Temp = UID;
		for (k = 0; k < 4;k ++)
        {
            if ((*UID_Temp++) != UIDlist[i][k])
            {
				break;
            }
			return 1;
       }
    }
    return 0;
}